'----------------------------------------------
' Name: Ali Karbassi
' Date: January 25, 2007
' Description: Test 1
'              form frmButton
'----------------------------------------------
Public Class frmButton

   Private Sub EXITToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
   Handles EXITToolStripMenuItem.Click

      Application.Exit()

   End Sub

   Private Sub SWITCHToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
   Handles SWITCHToolStripMenuItem.Click

      Me.Hide()
      frmJump.Show()

   End Sub

   Private Sub CREATEToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
   Handles CREATEToolStripMenuItem.Click
      If btnList.Count >= maxButtons Then

         MsgBox("There are " & maxButtons & " buttons already!", MsgBoxStyle.OkOnly)

      ElseIf btnList.Contains(txtKey.Text) Then

         MsgBox("A button with this key already exists. Use a different key please.", MsgBoxStyle.OkOnly)

      ElseIf txtKey.Text.Trim.Length <= 0 Then

         MsgBox("Enter a key please!", MsgBoxStyle.Information)

      Else

         Dim NewButton As New Button

         ' Create the new button
         NewButton.Text = Trim(txtCaption.Text)
         NewButton.Size = btnSize
         NewButton.Tag = 1
         NewButton.Location = New Point(100, 100)
         AddHandler NewButton.Click, AddressOf frmJump.btnHandler

         ' Put the button on the form
         frmJump.Controls.Add(NewButton)

         ' Put the button in the Sorted List
         btnList.Add(txtKey.Text, NewButton)

         frmJumpSettings()

      End If
   End Sub

   ''' <summary>
   ''' Arranges the buttons and sets the styles of them.
   ''' </summary>
   ''' <remarks></remarks>
   Private Sub frmJumpSettings()

      ' Arrange the buttons
      frmJump.ArrangeButtons()

   End Sub

   Private Sub REMOVEToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
   Handles REMOVEToolStripMenuItem.Click

      If txtKey.Text.Trim.Length <= 0 Then

         MsgBox("You must specify the Key!", MsgBoxStyle.Exclamation)

      ElseIf Not btnList.Contains(txtKey.Text) Then

         MsgBox("No buttons have the key: " & txtKey.Text, MsgBoxStyle.OkOnly)

      Else

         ' Remove the button from the form
         frmJump.Controls.Remove(btnList(txtKey.Text))

         ' Remove the box in the Sorted List
         btnList.Remove(txtKey.Text)

         frmJumpSettings()

      End If
   End Sub
End Class
